﻿using Cxuu.Models;
using Cxuu.Service;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;

namespace Cxuu.Web.Home
{
    [Area("Home")]
    public class InfoController : Base
    {
        private readonly ContentService _contentService;
        private readonly ContentCateService _contentCateService;

        public InfoController(ContentService contentService, ContentCateService contentCateService)
        {
            _contentService = contentService;
            _contentCateService = contentCateService;
        }

        /// <summary>
        /// 根据ID查询详细内容
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> IndexAsync(int id = 0)
        {
            if (id <= 0)
            {
                return Ok("请勿非法输入！");
            }
            ViewContentAndContent article = await _contentService.GetAsync(id);
            if (article == null)
            {
                return NotFound();
            }
            ContentCate cateInfo = await _contentCateService.GetOneAsync(article.Cid);
            ViewBag.info = article;
            ViewBag.cateInfo = cateInfo;
            return View();
        }

    }
}
